package com.csdj.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csdj.dto.OrderTypes;
import com.csdj.dto.orderPay;
import com.csdj.mapper.SyMetertypeMapper;
import com.csdj.pojo.BeOrder;
import com.csdj.pojo.SyMetertype;
import com.csdj.service.BeOrderService;
import com.csdj.mapper.BeOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author 叶涵
 * @description 针对表【be_order】的数据库操作Service实现
 * @createDate 2023-08-24 15:13:39
 */
@Service
public class BeOrderServiceImpl extends ServiceImpl<BeOrderMapper, BeOrder>
        implements BeOrderService {
    @Autowired
    private BeOrderMapper beOrderMapper;
    @Autowired
    private SyMetertypeMapper syMetertypeMapper;
    @Override
    public BeOrder getByIdCx(String orderNo) {
        BeOrder beOrder = beOrderMapper.selectById(orderNo);
        beOrder.setSyMetertype(syMetertypeMapper.selectById(beOrder.getMeterTypeID()));
        return beOrder;
    }

    @Override
    public List<orderPay> getAll(List<String> list, String timeStar, String timeEnd,Integer pageNum,Integer pageSize) {

        return beOrderMapper.getAll(list,timeStar,timeEnd,pageNum,pageSize);
    }

    @Override
    public List<OrderTypes> getAllOrder() {
        List<OrderTypes> list = beOrderMapper.getAllOrder();
        if(list.size()!=8){
            int num=-2;
            OrderTypes orderTypes=new OrderTypes(9,0,0,0,0,0,0,0);
            for (int i = 0; i < list.size(); i++) {
                if(list.get(i)!=null) {
                    num++;
                    if (list.get(i).getOrderType() != num) {
                        OrderTypes o = new OrderTypes(num, 0, 0, 0, 0, 0, 0, 0);
                        list.add(i, o);
                    }else{
                        if(list.get(i).getOrderType()!=-1 || list.get(i).getOrderType()!=0) {
                            orderTypes.setNewhu(orderTypes.getNewhu() + list.get(i).getNewhu());
                            orderTypes.setGuohu(orderTypes.getGuohu() + list.get(i).getGuohu());
                            orderTypes.setDaiko(orderTypes.getDaiko() + list.get(i).getDaiko());
                            orderTypes.setFenhu(orderTypes.getFenhu() + list.get(i).getFenhu());
                            orderTypes.setChongqian(orderTypes.getChongqian() + list.get(i).getChongqian());
                            orderTypes.setXiaohu(orderTypes.getXiaohu() + list.get(i).getXiaohu());
                            orderTypes.setHuanbiao(orderTypes.getHuanbiao() + list.get(i).getHuanbiao());
                        }
                    }
                }
            }
            //调整位置
            list.add(list.get(1));
            list.add(list.get(0));
            list.remove(0);
            list.remove(0);
            list.add(7,orderTypes);
        }
        return list;
    }
}




